package adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import java.util.List;

import beans.OperateGoodsDetailsBean;
import butterknife.BindView;
import custom.BaseRecyclerAdapter;

/**
 * Created by Administrator on 2018/5/11.
 */

public class CommonTableHeadAdapter extends BaseRecyclerAdapter<CommonTableHeadAdapter.CommonViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<OperateGoodsDetailsBean.DataBean> list;
    private OnClickListener onClickListener;

    public CommonTableHeadAdapter(Context mContext, List<OperateGoodsDetailsBean.DataBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater=LayoutInflater.from(mContext);
    }

    @Override
    public CommonViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        CommonViewHolder viewHolder = new CommonViewHolder(inflater.inflate(R.layout.adapter_common_table_head, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final CommonViewHolder viewHolder, final int position) {
        OperateGoodsDetailsBean.DataBean bean = list.get(position);
        viewHolder.tvCabinetNumber.setText(String.valueOf(bean.getSelectCabinet()));
        viewHolder.tvName.setText(bean.getGoodName());
        viewHolder.tvSpecification.setText(bean.getSpecification());
        viewHolder.tvSupplier.setText(bean.getManufacturer());
        viewHolder.tvCount.setText(String.valueOf(bean.getNumber()));
        viewHolder.tvUnit.setText(bean.getGoodsUnit());
        if (position % 2 == 0) {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.partLineBackground));
        } else {
            viewHolder.linearLayout.setBackgroundColor(mContext.getResources().getColor(R.color.white));
        }

//        viewHolder.tvName.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                onClickListener.onShowDetail(position, viewHolder.tvName, 380);
//                return true;
//            }
//        });
//
//        viewHolder.tvSpecification.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                onClickListener.onShowDetail(position, viewHolder.tvSpecification, 540);
//                return true;
//            }
//        });
//
//        viewHolder.tvSupplier.setOnLongClickListener(new View.OnLongClickListener() {
//            @Override
//            public boolean onLongClick(View v) {
//                onClickListener.onShowDetail(position, viewHolder.tvSupplier, 740);
//                return true;
//            }
//        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

   public void addData(List<OperateGoodsDetailsBean.DataBean> list){
       if (list!=null){
           this.list.addAll(list);
           notifyDataSetChanged();
       }
   }

    class CommonViewHolder extends BaseRecyclerAdapter.BaseViewHolder {
        @BindView(R.id.tv_adapter_common_cabinet_number)
        TextView tvCabinetNumber;
        @BindView(R.id.tv_adapter_common_name)
        TextView tvName;
        @BindView(R.id.tv_adapter_common_specification)
        TextView tvSpecification;
        @BindView(R.id.tv_adapter_common_supplier)
        TextView tvSupplier;
        @BindView(R.id.tv_adapter_common_count)
        TextView tvCount;
        @BindView(R.id.tv_adapter_common_unit)
        TextView tvUnit;
        @BindView(R.id.ll_adapter_common_title)
        LinearLayout linearLayout;
        public CommonViewHolder(View itemView) {
            super(itemView);
        }
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    public interface OnClickListener {
        //        void onShowDetailSpecification(int position, TextView view);
        void onShowDetail(int position, TextView view, int xOffWidth);
        //        void onShowDetailSupplier(int position, TextView view);
    }
}
